home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
borland
/
prbgi097.zip
/
PASCAL.ZIP
/
BGIDEMO.PAS
next >
Wrap
Pascal/Delphi Source File
|
1992-12-15
|
49KB
|
1,740 lines
{ This program is not mine.
It was included with Turbo Pascal 6.0
and I only modified it a little to demonstrate
features of my PRINTBGI library.
It is included here for demonstration only
and cannot be used for any other purposes. ( Could it? ).
Original Copyright notice follows.
}
{ Turbo Graphics }
{ Copyright (c) 1985, 1990 by Borland International, Inc. }
program BGIDemo;
(*
Turbo Pascal 6.0 Borland Graphics Interface (BGI) demonstration
program. This program shows how to use many features of
the Graph unit.
NOTE: to have this demo use the IBM8514 driver, specify a
conditional define constant "Use8514" (using the {$DEFINE}
directive or Options\Compiler\Conditional defines) and then
re-compile.
*)
uses
Crt, Dos, Graph, PRTgraph,Pdrivers,UserUnit;
const
{ The five fonts available }
Fonts : array[0..4] of string[13] =
('DefaultFont', 'TriplexFont', 'SmallFont', 'SansSerifFont', 'GothicFont');
{ The five predefined line styles supported }
LineStyles : array[0..4] of string[9] =
('SolidLn', 'DottedLn', 'CenterLn', 'DashedLn', 'UserBitLn');
{ The twelve predefined fill styles supported }
FillStyles : array[0..11] of string[14] =
('EmptyFill', 'SolidFill', 'LineFill', 'LtSlashFill', 'SlashFill',
'BkSlashFill', 'LtBkSlashFill', 'HatchFill', 'XHatchFill',
'InterleaveFill', 'WideDotFill', 'CloseDotFill');
{ The two text directions available }
TextDirect : array[0..1] of string[8] = ('HorizDir', 'VertDir');
{ The Horizontal text justifications available }
HorizJust : array[0..2] of string[10] = ('LeftText', 'CenterText', 'RightText');
{ The vertical text justifications available }
VertJust : array[0..2] of string[10] = ('BottomText', 'CenterText', 'TopText');
var
PathToDriver : string; { Stores the DOS path to *.BGI & *.CHR }
var
GraphDriver : integer; { The Graphics device driver }
GraphMode : integer; { The Graphics mode value }
(* MaxX, MaxY : word; *) { The maximum resolution of the screen }
function MaxX:integer;
begin MaxX:=getmaxX; end;
function MaxY:integer;
begin MaxY:=getmaxY; end;
var
ErrorCode : integer; { Reports any graphics errors }
(* MaxColor : word; *) { The maximum color value available }
function MaxColor:integer;
begin MaxColor:=getmaxColor; end;
var
OldExitProc : Pointer; { Saves exit procedure address }
{$F+}
procedure MyExitProc;
var rc: integer;
begin
ExitProc := OldExitProc; { Restore exit procedure address }
rc:=BGI_CloseGraph; { Shut down the graphics system }
end; { MyExitProc }
{$F-}
VAR
PRTno: word;
PRTmode: integer;
OutName: PathStr;
Const
picwidth : integer = 4000;
picheight : integer =3000;
leftmargin : integer =0;
topmargin : integer =0;
PicRotate : integer =0;
PicInverse : integer =1;
{-------------------------------}
Procedure ReadInt(var n: integer);
{-------------------------------}
var x: integer;
c: char;
Begin
{$ifdef ver60 }
asm @@lp:;
mov AH,1; { nondestructive keyboard read }
int $16; { BIOS Kbd intr }
jz @@lp;
mov c,AL
end;
if c = ^M then
begin (* user pressed ENTER - don't change old value *)
c := ReadKey;
writeln(n);
end
else
{$endif }
begin
{$I- }
ReadLn(x);
{$I+ }
if IOresult = 0 then n:=x;
end;
End;
(*-----------------------*)
Procedure AskOfParameters;
(*-----------------------*)
var
c: char;
MAXmode : integer;
modename : stringPtr;
rc : integer;
s: PathStr;
Begin
clrscr;
write ( ' Output device name [', OutName, '] ' );
ReadLn ( s ); if length(s)<>0 then OutName:=s;
rc := PRT_SetOutName ( OutName );
writeln;
writeln ( ' Choose printer mode operation' );
rc := PRT_MaxMode ( PRTno, MAXmode );
for PRTmode:=0 to MAXmode do
begin
{$V- }
rc := PRT_ModeName(PRTno,PRTmode,modename );
{$V+ }
writeln ( ' ', PRTmode:2,' - ', modename^ );
end;
PRTmode:=MAXmode+1;
repeat
c:=ReadKey;
if c=#0 then c:=ReadKey
else if ord(c)-ord('0') <= MAXmode then PRTmode := ord(c)-ord('0');
until (PRTmode<=MAXmode) and (PRTmode>=0);
writeln;
write ( ' Picture width in 1/1000 inch [', picwidth, '] ' );
ReadInt ( picwidth );
write ( ' Picture height in 1/1000 inch [', picheight, '] ' );
ReadInt ( picheight );
write ( ' Top margin in 1/1000 inch [', topmargin, '] ' );
ReadInt ( topmargin );
write ( ' Left margin in 1/1000 inch [', leftmargin, '] ' );
ReadInt ( leftmargin );
write ( ' Rotate picture [', PicRotate, '] ' );
ReadInt ( PicRotate );
write ( ' Inverse picture [', PicInverse, '] ' );
ReadInt ( PicInverse );
write ( ' Screen Preview [', ScreenPreview, '] ' );
ReadInt ( ScreenPreview );
write ( ' PCX mode [', PCXmode, '] ' );
ReadInt ( PCXmode );
End;
CONST
printing: boolean=false;
asking: boolean=false;
var
PRT_drv: integer;
(*---------------------------------*)
Procedure DrawAndPrint ( func: DrawFuncT );
(*---------------------------------*)
const
Seed = 1964;
var
rc : integer;
BGIPRT_mode,mode: integer;
PicMode : integer;
c: char;
opf: PRT_UserPrintFuncP;
imagePtr1,imagePtr2: pointer;
s: string[7];
Begin
BGIPRT_mode := 0;
repeat
asking:=false;
printing:=false;
RandSeed := Seed;
rc:=func(nil);
if asking then
begin
mode := BGI_getgraphmode(0,0);
restorecrtmode;
AskOfParameters;
BGI_setgraphmode( mode );
end;
if ( printing ) then (* Have user pressed Ctrl-P ? *)
begin
Outmsg('Creating bit image map','Please wait',@imagePtr1);
RandSeed := Seed;
PicMode := 0;
if PicRotate<>0 then PicMode := PicMode or PRT_ROTATE;
if PicInverse<>0 then PicMode := PicMode or PRT_INVERSE;
rc:=PRT_SetDriver ( PRTno, PRTmode,picwidth,picheight, PicMode );
rc:=PRT_SetMargins ( leftmargin, topmargin );
opf:=PRT_SetUserPrintFunc(PRT_ScreenPreview);
PRT_HaltPrinting := 0; { reset ctrl-break flag }
rc:=PRT_PrintBGI ( PRT_drv, BGIPRT_mode, PathToDriver, func, nil );
if ( rc<>0 ) then
begin
Str(rc:3,s);
OutMsg (' error code '+s, PRT_errormsg(rc), @imagePtr2 );
c:=ReadKey; while KeyPressed do c:=ReadKey;
CloseOutMsg ( @imagePtr2 );
end;
CloseOutmsg( @imagePtr1);
end;
until ( not asking and not printing );
End;
(*-----------------*)
Procedure PRT_Initialize;
(*-----------------*)
var
PRTname: stringPtr;
MaxPrinterNo: integer;
rc: integer;
c: char;
Begin
OutName := 'PRN';
{ rc:=PRT_LinkDrivers; } { link printers definitions }
rc:=PRT_ReadDrivers(getenv('BGIPATH'),'Printers.Def');
if rc<>0 then
begin
writeln ('Sorry - I can''t find drivers defintion file' );
halt(12);
end;
MaxPrinterNo := PRT_MaxDriver;
clrscr;
writeln;
writeln ( 'This is a sample program (developed from Borland''s BGIDEMO.PAS)' );
writeln ( 'demonstrating some of the features of PrintBGI toolkit' );
writeln ( 'Hope you''ll find it usefull (the whole package not this program,' );
writeln ( 'of course).' );
writeln;
writeln ( 'Please, let me know if this program does not work with your printer.');
writeln ( 'To contact me write to RESZTAK@PLUMCS11.bitnet');
writeln;
writeln ( ' Press any key to continue');
c:=ReadKey; while KeyPressed do c:=ReadKey;
clrscr;
writeln ( ' Choose printer type' );
writeln;
for PRTno:=1 to MaxPrinterNo do
begin
rc := PRT_DriverName(PRTno,PRTname);
writeln ( ' ', PRTno, ' - ', PRTname^ );
end;
repeat
Readln(PRTno);
until ( (PRTno<=MaxPrinterNo) and (PRTno>0) );
clrscr;
PRT_drv := Detect; { needed if you don't want to link BitImage driver }
PRT_drv := PRT_installuserdriver ( 'BitImage', NIL );
rc := PRT_registerbgidriver ( @BitImage );
AskOfParameters;
writeln;
writeln ( ' You will be able to change above parameters by pressing Ctrl-C.' );
writeln;
writeln ( ' Press any key to continue');
c:=ReadKey;while KeyPressed do c:=ReadKey;
End;
proced